package wolfUndSchafe;

public class MoveRules
{
  public static boolean isValidSheepMove(String[] field, int from, int to)
  {
    // Feld frei?
    if(!isFreeSpot(to, field))
      return false;

    // Erlaubte Bewegung?
    else if((from == 0 && to > 3)
        || (from == 1 && (to > 5 || to == 3 || to == 0))
        || (from == 2 && (to > 5 || to == 4 || to == 0))
        || (from == 3 && to != 2 && to != 5 && to != 6)
        || (from == 4 && to != 5 && to != 7)
        || (from == 5 && (to < 4 || to == 10))
        || (from == 6 && to != 5 && to != 9)
        || (from == 7 && to != 8 && to != 10) || (from == 8 && (to < 7))
        || (from == 9 && (to < 8)) || (from == 10))
      return false;
    
    return true;
  }

  public static boolean isValidWolfMove(String[] field, int from, int to)
  {
    // Feld frei?
    if(!isFreeSpot(to, field))
      return false;

    // Erlaubte Bewegung?
    else if((from == 0 && to > 3) || (from == 1 && (to > 5 || to == 3))
        || (from == 2 && (to > 5 || to == 4))
        || (from == 3 && (to > 6 || to == 1 || to == 4))
        || (from == 4 && to != 1 && to != 5 && to != 7)
        || (from == 5 && (to == 0 || to == 10))
        || (from == 6 && to != 3 && to != 5 && to != 9)
        || (from == 7 && (to < 4 || to == 6 || to == 9))
        || (from == 8 && (to < 5 || to == 6))
        || (from == 9 && (to < 5 || to == 7))
        || (from == 10 && to < 7))
      return false;
    
    return true;
  }

  // Ist angegebenes Feld frei?
  public static boolean isFreeSpot(int position, String[] field)
  {
    if(field[position].contains("SHEEP") || field[position].contains("WOLF"))
      return false;
    
    return true;
  }

  // Befindet sich der Wolf in einer "Schachmatt-Position"?
  public static boolean wolfIsCheckmate(int wolfPosition, String[] field)
  {
    if(wolfPosition == 4 && !isFreeSpot(1, field) && !isFreeSpot(5, field)
        && !isFreeSpot(7, field) || wolfPosition == 6 && !isFreeSpot(3, field)
        && !isFreeSpot(5, field) && !isFreeSpot(9, field) || wolfPosition == 10
        && !isFreeSpot(7, field) && !isFreeSpot(8, field)
        && !isFreeSpot(9, field))
      return true;
    
    return false;
  }

}
